﻿/*
SCUMMActionBar: This is the handler of the actions bar.
Controls the current selected action and contains the status bar
wich shows it.
*/
import SCUMMGameControl.SCUMMActionDescriptor;
import SCUMMCore.*;
import SCUMMCore.States.*;
import SCUMMGameControl.SCUMMDialogueMenu;
class SCUMMGameControl.SCUMMActionBar extends SCUMMObject {
	public var nCurrentAction:Number;
	public var oActionParameter1:SCUMMObject;
	public var oActionParameter2:SCUMMObject;
	public var oDialogueMenu:SCUMMDialogueMenu;
	private var nLastFrame:Number;
	private var bEnabled:Boolean;
	public function SCUMMActionBar(pmcActionBar:MovieClip) {
		this.bEnabled = true;
		//We don't want execute the Super constructor ;-)
		this.mc = pmcActionBar;
		nCurrentAction = 0;
		//this is very important, because "this" is not visible from
		//functions defined in constructor.
		var oSelfReference:SCUMMActionBar = this;
		/*
		the status basr changes his state depending the status of the game
		*/
		this.mc.onEnterFrame = function() {
			if (_global.SCUMMGame.isExploring() && oSelfReference.isEnabled()) {
				if (_global.ActionBar.mc._currentframe != "Exploring") {
					this.gotoAndStop("Exploring");
				}
				oSelfReference.updateStatusBar();
			} else if (_global.SCUMMGame.isTalking() && oSelfReference.isEnabled()) {
				if (_global.ActionBar.mc._currentframe != 2) {
					this.gotoAndStop("Talking");
					var sDialogueName:String;
					var sDialogueStatus:String;
					if (!_global.SCUMMGame.oFlagContainer["dialog_status"+_global.SCUMMGame.getOCurrentActorTalking().name]) {
						_global.SCUMMGame.oFlagContainer["dialog_status"+_global.SCUMMGame.getOCurrentActorTalking().name] = 1;
					}
					sDialogueStatus = _global.SCUMMGame.oFlagContainer["dialog_status"+_global.SCUMMGame.getOCurrentActorTalking().name];
					sDialogueName = "dialogue_"+_global.SCUMMGame.getOCurrentActorTalking().name+"_"+sDialogueStatus;
					oSelfReference.mc.dialogue_menu_container.gotoAndStop(sDialogueName);
				}
			}
		};
	}
	private function updateStatusBar() {
		if (oActionParameter2 != undefined) {
			if (oActionParameter2.name != oActionParameter1.name && oActionParameter1!=undefined) {
				writeOnStatusBar(SCUMMActionDescriptor.getStatusText(nCurrentAction)+" "+oActionParameter2.name+" con "+oActionParameter1.name);
			} else {
				writeOnStatusBar(SCUMMActionDescriptor.getStatusText(nCurrentAction)+" "+oActionParameter2.name+" con ");
			}
		} else if (oActionParameter1 != undefined && oActionParameter2.name != oActionParameter1.name) {
			writeOnStatusBar(SCUMMActionDescriptor.getStatusText(nCurrentAction)+" "+oActionParameter1.name);
		} else {
			writeOnStatusBar(SCUMMActionDescriptor.getStatusText(nCurrentAction));
		}
	}
	public function writeOnStatusBar(psTextToWrite:String) {
		this.mc.statusBar.text = psTextToWrite;
	}
	public function setCurrentAction(nCurrentAction:Number):Void {
		this.nCurrentAction = nCurrentAction;
		updateStatusBar();
	}
	public function getCurrentAction():Number {
		return this.nCurrentAction;
	}
	public function getOActionParameter1():SCUMMObject {
		return oActionParameter1;
	}
	public function setOActionParameter1(oActionParameter1:SCUMMObject):Void {
		this.oActionParameter1 = oActionParameter1;
		updateStatusBar();
	}
	public function getOActionParameter2():SCUMMObject {
		return oActionParameter2;
	}
	public function setOActionParameter2(oActionParameter2:SCUMMObject):Void {
		this.oActionParameter2 = oActionParameter2;
		updateStatusBar();
	}
	/*
	Author: Pablo Weremczuk
	Disables the action bars, no one button is shown
	*/
	function disable() {
		this.bEnabled = false;
		//this.nLastFrame = this.mc._currentframe;
		this.mc.disable_square.gotoAndStop("disabled");
	}
	/*
	Author: Pablo Weremczuk
	This function enables the action bar, using the nLasFrame var
	*/
	function enable() {
		this.bEnabled = true;
		this.mc.disable_square.gotoAndStop("enabled");
	}
	/*
	Usefull to check id the actionsbar is disabled 
	
	@author: Pablo Weremczuk
	@returns: true if enabled
	 */
	function isEnabled():Boolean {
		return this.bEnabled;
	}
}
